<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model layout="inline" ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <!-- <a-form-model-item label="导入时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="importStartTime">
              <j-date placeholder="请选择导入开始时间"  v-model="model.importStartTime" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%" />
            </a-form-model-item> -->
            <!-- <a-col :span="24">
            <a-form-model-item label="导入结束时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="importEndTime">
              <j-date placeholder="请选择导入结束时间"  v-model="model.importEndTime" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%" />
            </a-form-model-item>
          </a-col> -->
            <a-form-model-item label="可导入时间" prop="importStartTime">
              <j-date
                placeholder="请选择开始时间"
                class="query-group-cust"
                v-model="model.importStartTime"
                date-format="YYYY-MM-DD HH:mm:ss"
                style="width: 100%"
                show-time
              ></j-date>
            </a-form-model-item>
            <a-form-model-item>
              <span class="query-group-split-cust"></span>
            </a-form-model-item>
            <a-form-model-item prop="importEndTime">
              <j-date
                placeholder="请选择结束时间"
                class="query-group-cust"
                v-model="model.importEndTime"
                date-format="YYYY-MM-DD HH:mm:ss"
                style="width: 100%"
                show-time
              ></j-date>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>
import { httpAction, getAction } from '@/api/manage'
import { validateDuplicateValue } from '@/utils/util'
export default {
  name: 'FinanceAmazonOrderConfigForm',
  components: {},

  props: {
    //表单禁用
    disabled: {
      type: Boolean,
      default: false,
      required: false,
    },
  },
  data() {
    return {
      model: {},
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
      confirmLoading: false,
      validatorRules: {
        importStartTime: [{ required: true, message: '请选择开始时间' }],
        importEndTime: [{ required: true, message: '请选择结束时间' }],
      },
      columns: [],
      url: {
        list: '/amazon/financeAmazonOrderConfig/list',
        add: '/amazon/financeAmazonOrderConfig/add',
        edit: '/amazon/financeAmazonOrderConfig/edit',
        queryById: '/amazon/financeAmazonOrderConfig/queryById',
      },
    }
  },
  computed: {
    formDisabled() {
      return this.disabled
    },
  },
  created() {
    //备份model原始值
    this.modelDefault = JSON.parse(JSON.stringify(this.model))
    this.getImportTime()
  },
  methods: {
    add() {
      this.edit(this.modelDefault)
    },
    edit(record) {
      this.model = Object.assign({}, record)
      this.visible = true
    },
    //获取导入时间
    getImportTime() {
      this.loading = true
      getAction(this.url.list).then((res) => {
        if (res.success) {     
          this.model = (res.result.records && res.result.records.length>0) ? res.result.records[0] : {}   
        }
        if (res.code === 510) {
          this.$message.warning(res.message)
        }
        this.loading = false
      })
    },
    submitForm() {
      const that = this
      // 触发表单验证
      this.$refs.form.validate((valid) => {
        if (valid) {
          that.confirmLoading = true
          let httpurl = ''
          let method = ''
          if (!this.model.id) {
            httpurl += this.url.add
            method = 'post'
          } else {
            httpurl += this.url.edit
            method = 'put'
          }
          httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })

        }
      })
    },
  },
}
</script>